package com.objecteffects.ilmp.web.action;

import com.google.inject.Inject;

import com.objecteffects.ilmp.model.UserEntity;
import com.objecteffects.ilmp.service.UserEntityService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sourceforge.stripes.action.Resolution;

/**
 * @author Rusty Wright
 */
public class UserEntityActionBean extends BaseActionBean {
    private final transient Logger log = LoggerFactory
        .getLogger(UserEntityActionBean.class);

    private final UserEntityService userEntityService;

    private Long userId;
    private UserEntity userEntity;

    @Inject
    UserEntityActionBean(final UserEntityService _userEntityService) {
        this.userEntityService = _userEntityService;
    }

    public Resolution setup() {
        this.userId = this.getContext().getUserId();

        this.log.debug("userId: {}", this.userId);

        if (this.userId != null) {
            this.userEntity = this.userEntityService.findById(this.userId);
        }

        return null;
    }

    public String getTumblrName() {
        if (this.userId == null) {
            this.log.debug("userId is null");

            return null;
        }

        if (this.userEntity == null) {
            this.log.debug("userEntity is null");

            return null;
        }

        return this.userEntity.getTumblrName();
    }

    public String getUserName() {
        if (this.userId == null) {
            this.log.debug("userId is null");

            return null;
        }

        if (this.userEntity == null) {
            this.log.debug("userEntity is null");

            return null;
        }

        return this.userEntity.getUserName();
    }
}
